home *** CD-ROM | disk | FTP | other *** search
- /* File: LibraryManagerClasses.h
-
- Contains: Declarations for ASLM classes
-
- Copyright: © 1991-1993 by Apple Computer, Inc., all rights reserved.
-
-
- */
-
- #ifndef __LIBRARYMANAGERCLASSES__
- #define __LIBRARYMANAGERCLASSES__
-
- #ifndef __LIBRARYMANAGER__
- #include <LibraryManager.h>
- #endif
-
- /*******************************************************************************
- ** Forward class declarations
- ********************************************************************************/
-
- #ifdef __cplusplus
- class TOperation;
- class TStandardPool;
- class TTraceLog;
- class TTaskScheduler;
- class TArbitrator;
- class TTime;
- class TPoolNotifier;
- class TRequestToken;
- class TToken;
- #else
- typedef void TOperation;
- typedef void TTraceLog;
- typedef void TArbitrator;
- typedef void TTaskScheduler;
- #endif
-
- /*******************************************************************************
- ** Some typedefs and enums
- ********************************************************************************/
-
- //
- // PointerType is mainly used for the TCollection::DeleteAll method so the collection
- // knows what type of objects are in the collection so it can do the proper cast
- // and call the destructor (if it really is an object).
- //
- typedef int PointerType;
-
- #define kVoidPointer ((PointerType)0) /* a non-object pointer */
- #define kTDynamicPointer ((PointerType)1) /* SingleObject with vtable first */
- #define kTSCDynamicPointer ((PointerType)1) /* subclass of TSCDynamic */
- #define kTSCPointer ((PointerType)2) /* A Think C++ Object */
- #define kTStdDynamicPointer ((PointerType)3) /* non-SingleObject with vtable first */
-
- typedef unsigned long EventCode;
-
- #define kTokenNotification ((EventCode)0x40000001)
- #define kLowPoolMemoryEvent ((EventCode)0x40000002)
- #define kHighPoolMemoryEvent ((EventCode)0x40000003)
- #define kDownsizePoolEvent ((EventCode)0x40000004)
- #define kDeathEvent ((EventCode)0x40000005)
-
- typedef void (* MPWC ProcessProcPtr)(TOperation*);
-
- typedef unsigned long (* MPWC HashProcPtr)(const void*);
- typedef Boolean (* MPWC IsEqualProcPtr)(const void* ref, const void* toComp);
- typedef int (* MPWC CompareProcPtr)(const void* ref, const void* toComp);
-
- // Below is a typedef for a pointer to a notify method for an object. Ignore the
- // fact the the typedef claims that it needs to be a TDynamic method. It can be
- // any kind of class. The only caveat is that if the NotifyMethod is a virtual
- // function, the vtable for the object must be the first field of the object.
- // You can force the vtable to be first by creating a base class that has atleast
- // one virtual function and no data members, like TDynamic does.
- #ifdef __cplusplus
- typedef void (TDynamic::* MPWC NotifyMethodPtr)(EventCode, OSErrParm, void* notifyData);
- typedef NotifyMethodPtr NotifyMethod;
- #endif
- typedef void (* MPWC NotifyProcPtr)(void* refPtr, EventCode, OSErrParm, void* notifyData);
-
- //
- // These are for compatibility with ASLM 1.1
- //
- typedef ProcessProcPtr ProcessProc;
- typedef HashProcPtr HashProc;
- typedef IsEqualProcPtr IsEqualProc;
- typedef CompareProcPtr CompareProc;
- typedef NotifyProcPtr NotifyProc;
-
- /*******************************************************************************
- ** Some "C" Global routines
- ********************************************************************************/
-
- #ifdef __cplusplus
- extern "C"
- {
- #endif
- TTraceLog* GetGlobalTraceLog();
- void SetGlobalTraceLog(TTraceLog*);
- void Trace(const char *formatStr, ...);
-
- TArbitrator* GetGlobalArbitrator();
- TTaskScheduler* GetGlobalTaskScheduler();
- void DestroyPointer(void*, PointerType);
- #ifdef __cplusplus
- };
- #endif
-
- #ifdef __cplusplus
-
- /*******************************************************************************
- ** TMacSemaphore class
- **
- ** Since threads don't really exist on the Macintosh, these semaphores are
- ** done by shutting interrupts off to guarantee exclusivity. Therefore,
- ** the rule is - never hold one very long, since on the Macintosh
- ** it will degrade performance if you do.
- ********************************************************************************/
-
- #define kTMacSemaphoreID "!$sema,1.1"
-
- class TMacSemaphore : public TDynamic
- {
- public:
- MPWC TMacSemaphore();
- virtual ~ MPWC TMacSemaphore();
-
- virtual void MPWC Grab();
- virtual void MPWC Release();
- virtual Boolean MPWC GrabNoWait();
-
- private:
- TMacSemaphore(const TMacSemaphore&);
- void operator=(const TMacSemaphore&);
-
- short fSaveLevel;
- short fCount;
- };
-
- /*******************************************************************************
- ** CLASS TMatchObject
- **
- ** This object is the base class for any object which "knows" how
- ** to hash a specific object, as well as how to compare a
- ** 2nd object to the specific object.
- ********************************************************************************/
-
- #define kTMatchObjectID "!$mobj,1.1"
-
- class TMatchObject : public TDynamic
- {
- public:
- virtual ~ MPWC TMatchObject();
-
- // Default implementation is to return 0
- virtual unsigned long MPWC Hash() const;
- // Default implementation is to compare
- // address of "this" with address of the object
- virtual short MPWC Compare(const void*) const;
- // Default implementation is to call Compare
- virtual Boolean MPWC IsEqual(const void*) const;
-
- protected:
- TMatchObject();
- };
-
- /*******************************************************************************
- ** CLASS TProcMatchObject
- **
- ** This is a TMatchObject which takes a reference pointer and pointers to "C"
- ** functions to do the matching/hashing job.
- ********************************************************************************/
-
- #define kTProcMatchObjectID "!$pmob,1.1"
-
- class TProcMatchObject : public TMatchObject
- {
- public:
- MPWC TProcMatchObject(const void* ref, HashProcPtr = 0,
- CompareProcPtr = 0, IsEqualProcPtr = 0);
- virtual ~ MPWC TProcMatchObject();
-
- virtual unsigned long MPWC Hash() const;
- virtual short MPWC Compare(const void*) const;
- virtual Boolean MPWC IsEqual(const void*) const;
-
- void SetReferencePointer(const void*);
- void SetHashProc(HashProcPtr);
- void SetCompareProc(CompareProcPtr);
- void SetIsEqualProc(IsEqualProcPtr);
-
- const void* GetReferencePointer() const;
- HashProcPtr GetHashProc() const;
- CompareProcPtr GetCompareProc() const;
- IsEqualProcPtr GetIsEqualProc() const;
-
- private:
- const void* fRef;
- HashProcPtr fHashProc;
- CompareProcPtr fCompareProc;
- IsEqualProcPtr fIsEqualProc;
- };
-
-
- /* -------------------------------------------------------------------------
- Inline methods for TProcMatchObject
- ------------------------------------------------------------------------- */
-
- inline void TProcMatchObject::SetReferencePointer(const void* ref)
- {
- fRef = ref;
- }
-
- inline void TProcMatchObject::SetHashProc(HashProcPtr proc)
- {
- fHashProc = proc;
- }
-
- inline void TProcMatchObject::SetCompareProc(CompareProcPtr proc)
- {
- fCompareProc = proc;
- }
-
- inline void TProcMatchObject::SetIsEqualProc(IsEqualProcPtr proc)
- {
- fIsEqualProc = proc;
- }
-
- inline const void* TProcMatchObject::GetReferencePointer() const
- {
- return fRef;
- }
-
- inline HashProcPtr TProcMatchObject::GetHashProc() const
- {
- return fHashProc;
- }
-
- inline CompareProcPtr TProcMatchObject::GetCompareProc() const
- {
- return fCompareProc;
- }
-
- inline IsEqualProcPtr TProcMatchObject::GetIsEqualProc() const
- {
- return fIsEqualProc;
- }
-
- /*******************************************************************************
- ** CLASS THashObject
- **
- ** This object is the base class for any object which "knows" how
- ** to hash another object.
- ********************************************************************************/
-
- #define kTHashObjectID "!$hobj,1.1"
-
- class THashObject : public TDynamic
- {
- public:
- virtual ~ MPWC THashObject();
-
- virtual unsigned long MPWC Hash(const void*) const = 0;
-
- protected:
- MPWC THashObject();
- };
-
- /*******************************************************************************
- ** CLASS TProcHashObject
- **
- ** This is a THashObject which uses a "C" Procedure to hash objects.
- ********************************************************************************/
-
- #define kTProcHashObjectID "!$phob,1.1"
-
- class TProcHashObject : public THashObject
- {
- public:
- MPWC TProcHashObject(HashProcPtr);
- virtual ~ MPWC TProcHashObject();
-
- virtual unsigned long MPWC Hash(const void*) const;
-
- void SetHashProc(HashProcPtr);
- HashProcPtr GetHashProc() const;
-
- private:
- HashProcPtr fHashProc;
- };
-
- /* -------------------------------------------------------------------------
- Inline methods for TProcHashObject
- ------------------------------------------------------------------------- */
-
- inline void TProcHashObject::SetHashProc(HashProcPtr proc)
- {
- fHashProc = proc;
- }
-
- inline HashProcPtr TProcHashObject::GetHashProc() const
- {
- return fHashProc;
- }
-
- /*******************************************************************************
- ** CLASS TIterator
- **
- ** This class Iterates through a collection of objects. Since
- ** collections are "thread-safe", when the Next() method returns
- ** NULL, call IterationComplete(). If it returns true, then you were
- ** returned NULL because the iterator was done. Otherwise, you were
- ** returned NULL because the underlying collection changed.
- ** RemoveCurrentObject will return false if the collection changed
- ** before the remove could be done.
- ********************************************************************************/
-
- #define kTIteratorID "!$iter,1.1"
-
- class TIterator : public TDynamic
- {
- public:
- virtual ~ MPWC TIterator();
-
- virtual void MPWC Reset() = 0;
- virtual void* MPWC Next() = 0;
-
- virtual Boolean MPWC IterationComplete() const = 0;
- virtual Boolean MPWC RemoveCurrentObject() = 0;
-
- void SetMatchObject(TMatchObject*);
- TMatchObject* GetMatchObject() const;
-
- protected:
- MPWC TIterator();
-
- private:
- TMatchObject* fMatcher;
- };
-
- /* -------------------------------------------------------------------------
- Inline methods for TIterator
- ------------------------------------------------------------------------- */
-
- inline void TIterator::SetMatchObject(TMatchObject* theMatcher)
- {
- fMatcher = theMatcher;
- }
-
- inline TMatchObject* TIterator::GetMatchObject() const
- {
- return fMatcher;
- }
-
- /*******************************************************************************
- ** CLASS TCollection
- **
- ** This class defines the framework for all collections.
- ********************************************************************************/
-
- #define kTCollectionID "!$coll,1.1"
-
- class TCollection : public TDynamic
- {
- public:
- virtual ~ MPWC TCollection();
-
- size_t Count() const;
- Boolean IsEmpty() const;
- virtual TIterator* MPWC CreateIterator(TStandardPool*) = 0;
-
- virtual OSErr MPWC Add(void*);
- virtual OSErr MPWC AddUnique(void*, const TMatchObject&);
- virtual OSErr MPWC AddUnique(void*);
-
- virtual void MPWC RemoveAll();
- virtual void MPWC DeleteAll(PointerType = kTDynamicPointer);
- virtual void* MPWC Remove(const TMatchObject&) = 0;
- virtual void* MPWC Member(const TMatchObject&) = 0;
- virtual Boolean MPWC Remove(void*) = 0;
- virtual Boolean MPWC Member(const void*) = 0;
-
- virtual void* MPWC GetIndexedObject(size_t) const;
- void* operator[](size_t);
-
- long GetSeed() const;
- void Grab();
- void Release();
-
- protected:
- MPWC TCollection();
- virtual OSErr MPWC PrivateAdd(void*, long) = 0;
- virtual void MPWC KillAll(BooleanParm ifDel, PointerType) = 0;
-
- long fSeed;
- size_t fCount;
- TMacSemaphore fSemaphore;
- };
-
- /* -----------------------------------------------------------------
- Inline Methods for TCollection
- ----------------------------------------------------------------- */
-
- inline size_t TCollection::Count() const
- {
- return fCount;
- }
-
- inline Boolean TCollection::IsEmpty() const
- {
- return fCount == 0;
- }
-
- inline void* TCollection::operator[](size_t idx)
- {
- return GetIndexedObject(idx);
- }
-
- inline long TCollection::GetSeed() const
- {
- return fSeed;
- }
-
- inline void TCollection::Grab()
- {
- (&fSemaphore)->Grab();
- }
-
- inline void TCollection::Release()
- {
- (&fSemaphore)->Release();
- }
-
- /*******************************************************************************
- ** CLASS TLink
- **
- ** This class implements a link object which can be placed on a linked
- ** list. It is totally non-virtual since it is a trivial class and
- ** to keep it at 8 bytes in size.
- ********************************************************************************/
-
- class TLink
- {
- public:
- TLink(void* value);
- TLink(TLink* link, void* value);
- TLink(BooleanParm);
- TLink();
- ~TLink();
-
- void* operator new(size_t size, TMemoryPool*); // default size, from a pool
- void* operator new(size_t); // from default pool
- void operator delete(void* mem) {SLMDeleteOperator(mem);};
-
- void SetNext(TLink* link);
- TLink* GetNext() const;
-
- void* GetValue() const;
- void SetValue(void*);
-
- void Append(TLink* newLink); // append newLink after this
- void Remove(TLink* previous); // remove nextLink from list
-
- private:
- TLink* fNext;
- void* fValue;
- };
-
- /* -----------------------------------------------------------------
- Inline Methods for TLink
- ----------------------------------------------------------------- */
-
- inline void* TLink::operator new(size_t size, TMemoryPool* thePool)
- {
- return SLMNewOperator(size, thePool);
- }
-
- inline void* TLink::operator new(size_t size)
- {
- return SLMNewOperator(size, NULL);
- }
-
- inline TLink::TLink(BooleanParm)
- {}
-
- inline TLink::TLink()
- {
- fNext = NULL;
- fValue = NULL;
- }
-
- inline TLink::TLink(void* value)
- {
- fNext = NULL;
- fValue = value;
- }
-
- inline TLink::TLink(TLink* link, void* value)
- {
- fNext = link;
- fValue = value;
- }
-
- inline TLink::~TLink()
- {
- fNext = NULL;
- fValue = NULL;
- }
-
- inline void TLink::SetNext(TLink* link)
- {
- fNext = link;
- }
-
- inline TLink* TLink::GetNext() const
- {
- return fNext;
- }
-
- inline void* TLink::GetValue() const
- {
- return fValue;
- }
-
- inline void TLink::SetValue(void* obj)
- {
- fValue = obj;
- }
-
- inline void TLink::Append(TLink* newLink)
- {
- newLink->SetNext(fNext);
- fNext = newLink;
- }
-
- inline void TLink::Remove(TLink* previous)
- {
- TLink* link = previous->GetNext();
- previous->SetNext(fNext);
- link->SetNext(NULL);
- }
-
- /*******************************************************************************
- ** CLASS TPriorityLink
- **
- ** This class implements a link object which can be placed on a linked
- ** list, and can hold a timer or priority value.
- ********************************************************************************/
-
- #define kNormalPriority (((unsigned long)-1L) >> 1)
- #define kHighestPriority 0
- #define kLowestPriority ((unsigned long)-1L)
- #define kToLowerPriority 1
-
- class TPriorityLink : public TLink
- {
- public:
- TPriorityLink(BooleanParm);
- TPriorityLink(void* value);
- TPriorityLink(TLink* link, void* value);
- TPriorityLink();
-
- void SetPriority(unsigned long);
- unsigned long GetPriority() const;
-
- private:
- unsigned long fPriority;
- };
-
- /* -----------------------------------------------------------------
- Inline Methods for TPriorityLink
- ----------------------------------------------------------------- */
-
- inline TPriorityLink::TPriorityLink(BooleanParm val) : TLink(val)
- {}
-
- inline TPriorityLink::TPriorityLink()
- {
- fPriority = kNormalPriority;
- }
-
- inline TPriorityLink::TPriorityLink(TLink* link, void* value) :
- TLink(link, value)
- {
- fPriority = kNormalPriority;
- }
-
- inline TPriorityLink::TPriorityLink(void* value) : TLink(value)
- {
- fPriority = kNormalPriority;
- }
-
- inline void TPriorityLink::SetPriority(unsigned long pri)
- {
- fPriority = pri;
- }
-
- inline unsigned long TPriorityLink::GetPriority() const
- {
- return fPriority;
- }
-
- /*******************************************************************************
- ** CLASS TSimpleList
- **
- ** This class implements a simple linked list, which can have objects added
- ** at the front or the back of the list.
- ********************************************************************************/
-
- #define kTSimpleListID "!$slst,1.1"
-
- class TSimpleList : public TCollection
- {
- friend class TListIterator;
-
- public:
- MPWC TSimpleList();
- MPWC TSimpleList(TMemoryPool*);
- MPWC TSimpleList(TSimpleList*);
- virtual ~ MPWC TSimpleList();
-
- // TCollection overrides
-
- virtual TIterator* MPWC CreateIterator(TStandardPool*);
-
- virtual void* MPWC Remove(const TMatchObject&);
- virtual void* MPWC Member(const TMatchObject&);
- virtual Boolean MPWC Remove(void*);
- virtual Boolean MPWC Member(const void*);
-
- // New methods
-
- virtual TLink* MPWC MemberLink(const void*);
- virtual TLink* MPWC MemberLink(const TMatchObject&);
- virtual TLink* MPWC RemoveLink(void*);
- virtual TLink* MPWC RemoveLink(const TMatchObject&);
-
- virtual TLink* MPWC FirstLink() const;
- virtual TLink* MPWC LastLink() const;
- virtual TLink* MPWC RemoveFirstLink();
- virtual TLink* MPWC RemoveLastLink();
- virtual void MPWC AddLinkFirst(TLink*);
- virtual void MPWC AddLinkLast(TLink*);
-
- virtual void* MPWC First() const;
- virtual void* MPWC Last() const;
- virtual void* MPWC RemoveFirst();
- virtual void* MPWC RemoveLast();
- virtual OSErr MPWC AddFirst(void*);
- virtual OSErr MPWC AddLast(void*);
-
- void SetLinkPool(TMemoryPool*);
- TMemoryPool* GetLinkPool() const;
-
- protected:
- virtual OSErr MPWC PrivateAdd(void*, long);
- virtual void MPWC KillAll(BooleanParm ifDel, PointerType);
- virtual TLink* MPWC PrivateFind(const void*, const TMatchObject*, TLink**) const;
-
- private:
- TSimpleList(const TSimpleList&);
- void operator=(const TSimpleList&);
-
- protected:
-
- TLink* fList;
- TLink* fLastInList;
- TMemoryPool* fLinkPool;
- };
-
- /* -----------------------------------------------------------------
- Inline Methods for TSimpleList
- ----------------------------------------------------------------- */
-
- inline void TSimpleList::SetLinkPool(TMemoryPool* thePool)
- {
- fLinkPool = thePool;
- }
-
- inline TMemoryPool* TSimpleList::GetLinkPool() const
- {
- return fLinkPool;
- }
-
- /*******************************************************************************
- ** CLASS TLinkedList
- **
- ** This class adds the ability to do things with a linked list based on
- ** "after" or "before" rules.
- ********************************************************************************/
-
- #define kTLinkedListID "slm:coll$llst,1.1"
-
- class TLinkedList : public TSimpleList
- {
- public:
- MPWC TLinkedList();
- MPWC TLinkedList(TMemoryPool*);
- MPWC TLinkedList(TSimpleList*);
- virtual ~ MPWC TLinkedList();
-
- // New methods
-
- virtual void* MPWC After(const void* obj) const;
- virtual void* MPWC After(const TMatchObject&) const;
- virtual void* MPWC Before(const void* obj) const;
- virtual void* MPWC Before(const TMatchObject&) const;
-
- virtual Boolean MPWC AddLinkAfter(TLink*, const TMatchObject&);
- virtual Boolean MPWC AddLinkAfter(TLink*, const void* obj);
- virtual Boolean MPWC AddLinkBefore(TLink*, const TMatchObject&);
- virtual Boolean MPWC AddLinkBefore(TLink*, const void* obj);
- virtual OSErr MPWC AddAfter(void*, const TMatchObject&);
- virtual OSErr MPWC AddAfter(void*, const void* obj);
- virtual OSErr MPWC AddBefore(void*, const TMatchObject&);
- virtual OSErr MPWC AddBefore(void*, const void* obj);
-
- private:
- TLinkedList(const TLinkedList&);
- void operator=(const TLinkedList&);
- };
-
- /*******************************************************************************
- ** CLASS TPriorityList
- **
- ** This class implements a list where objects are sorted in order of a
- ** priority.
- ********************************************************************************/
-
- #define kTPriorityListID "!$plst,1.1"
-
- class TPriorityList : public TSimpleList
- {
- public:
- MPWC TPriorityList();
- MPWC TPriorityList(TMemoryPool*);
- MPWC TPriorityList(TPriorityList*);
- virtual ~ MPWC TPriorityList();
-
- // TLinkedList overrides
-
- virtual OSErr MPWC AddFirst(void*);
- virtual OSErr MPWC AddLast(void*);
- virtual void MPWC AddLinkFirst(TLink*);
- virtual void MPWC AddLinkLast(TLink*);
-
- // New methods
-
- virtual OSErr MPWC AddPrioritized(void*, unsigned long pri);
- virtual void MPWC AddLink(TPriorityLink*);
-
- private:
- TPriorityList(const TPriorityList&);
- void operator=(const TPriorityList&);
- virtual OSErr MPWC PrivateAdd(void*, long);
- };
-
- /*******************************************************************************
- ** CLASS TListIterator
- **
- ** This iterator is used to iterate all collection classes descending from
- ** TSimpleList.
- ********************************************************************************/
-
- #define kTListIteratorID "!$litr,1.1"
-
- class TListIterator : public TIterator
- {
- public:
- MPWC TListIterator(TSimpleList*);
- virtual ~ MPWC TListIterator();
-
- // TIterator Overrides
-
- virtual void MPWC Reset();
- virtual void* MPWC Next();
-
- virtual Boolean MPWC IterationComplete() const;
- virtual Boolean MPWC RemoveCurrentObject();
-
- // New methods
-
- virtual TLink* MPWC GetCurrentLink() const;
- void SetList(TSimpleList*);
-
- private:
- TListIterator(const TListIterator&);
- void operator=(const TListIterator&);
-
- virtual TLink* MPWC NextLink();
-
- TSimpleList* fList;
- TLink* fPrevLink;
- TLink* fCurLink;
- long fSeed;
- Boolean fComplete;
- Boolean fFiller;
- };
-
- /* -------------------------------------------------------------------------
- Inline methods for TListIterator
- ------------------------------------------------------------------------- */
-
- inline void TListIterator::SetList(TSimpleList* list)
- {
- fList = list;
- Reset();
- }
-
- /*******************************************************************************
- ** CLASS TArray
- **
- ** This class implements an array collection, where objects can be efficiently
- ** looked at by index, and are added to the end of the array. Deleting objects
- ** moves all higher-indexed objects down by 1 index number.
- ********************************************************************************/
-
- #define kTArrayID "slm:coll$arry,1.1"
-
- class TArray : public TCollection
- {
- friend class TArrayIterator;
-
- public:
- MPWC TArray();
- MPWC TArray(size_t size, TStandardPool* = NULL,
- int growBy = 0);
- virtual ~ MPWC TArray();
-
- virtual Boolean MPWC IsValid() const;
-
- TStandardPool* GetGrowPool() const;
-
- // TCollection overrides
-
- virtual TIterator* MPWC CreateIterator(TStandardPool*);
-
- virtual Boolean MPWC Remove(void*);
- virtual void* MPWC Remove(const TMatchObject&);
- virtual Boolean MPWC Member(const void*);
- virtual void* MPWC Member(const TMatchObject&);
-
- virtual void* MPWC GetIndexedObject(size_t) const;
-
- private:
- TArray(const TArray&);
- void operator=(const TArray&);
- void MPWC InitArray(size_t size, TStandardPool*, int growBy);
-
- protected:
- virtual void* MPWC MemberIndex(const void*, const TMatchObject*, size_t*);
- virtual void* MPWC PrivateRemove(void*, const TMatchObject*);
- virtual OSErr MPWC PrivateAdd(void*, long);
- virtual void MPWC KillAll(BooleanParm ifDel, PointerType);
- virtual Boolean MPWC Grow();
-
- void** fArray; // memory allocated for the array
- size_t fSize; // current size of the array
- long fGrowBy; // size to grow by if array is full
- };
-
- /*******************************************************************************
- ** CLASS TArrayIterator
- **
- ** This class Iterates through a TArray collection
- ********************************************************************************/
-
- #define kTArrayIteratorID "slm:coll$aitr,1.1"
-
- class TArrayIterator : public TIterator
- {
- public:
- MPWC TArrayIterator(TArray*);
- virtual ~ MPWC TArrayIterator();
-
- virtual void MPWC Reset();
- virtual void* MPWC Next();
-
- virtual Boolean MPWC IterationComplete() const;
- virtual Boolean MPWC RemoveCurrentObject();
-
- private:
- TArrayIterator(const TArrayIterator&);
- void operator=(const TArrayIterator&);
-
- private:
- TArray* fArray;
- size_t fCurIdx;
- long fSeed;
- Boolean fComplete;
- Boolean fFiller;
- };
-
- /*******************************************************************************
- ** Class THashList
- ********************************************************************************/
-
- #define kTHashListID "!$hsls,1.1"
-
- struct HashListInfo
- {
- size_t emptySlots; // number of empty slots in the hash list
- size_t singleSlots; // number of slots with only one entry
- size_t numChains; // number of slots with more than one entry
- size_t longestChain; // the longest chain
- size_t avgChain; // the average length of a chain
- };
-
- class THashList : public TCollection
- {
- friend class THashListIterator;
-
- protected:
- MPWC THashList(BooleanParm);
-
- public:
- MPWC THashList();
- MPWC THashList(THashObject*,
- size_t initialSize,
- TMemoryPool* = NULL);
- virtual ~ MPWC THashList();
-
- virtual Boolean MPWC IsValid() const;
-
- virtual OSErr MPWC Grow(size_t newSize);
-
- OSErr Rehash();
-
- void SetHashObject(THashObject*);
- TMemoryPool* GetLinkPool() const;
- THashObject* GetHashObject() const;
- size_t GetTableSize() const;
- void SetLinkPool(TMemoryPool*);
-
- virtual void MPWC GetHashListInfo(HashListInfo&) const;
-
- // TCollection Overrides
-
- virtual TIterator* MPWC CreateIterator(TStandardPool*);
-
- virtual void* MPWC Remove(const TMatchObject&);
- virtual void* MPWC Member(const TMatchObject&);
- virtual Boolean MPWC Remove(void*);
- virtual Boolean MPWC Member(const void*);
-
- protected:
- virtual OSErr MPWC PrivateAdd(void*, long);
- virtual void MPWC KillAll(BooleanParm ifDel, PointerType);
-
- virtual void* MPWC PrivateFind(const void*,
- const TMatchObject*,
- void** toDel);
-
- virtual Boolean MPWC IsPrime(size_t num);
- virtual size_t MPWC FixSize(size_t);
- unsigned long Hash(const void*);
-
- private:
- THashList(const THashList&);
- void operator=(const THashList&);
- void MPWC InitHashList(THashObject*, TMemoryPool*,
- size_t);
- protected:
- THashObject* fHasher;
- TMemoryPool* fLinkPool;
- void** fTable;
- size_t fTableSize;
- void** fGrowTable;
- size_t fGrowTableSize;
- Boolean fGrowInProgress;
- Boolean fFiller;
- };
-
- /* -------------------------------------------------------------------------
- Inline methods for THashList
- ------------------------------------------------------------------------- */
-
- inline void THashList::SetHashObject(THashObject* obj)
- {
- fHasher = obj;
- }
-
- inline THashObject* THashList::GetHashObject() const
- {
- return fHasher;
- }
-
- inline void THashList::SetLinkPool(TMemoryPool* pool)
- {
- fLinkPool = pool;
- }
-
- inline TMemoryPool* THashList::GetLinkPool() const
- {
- return fLinkPool;
- }
-
- inline size_t THashList::GetTableSize() const
- {
- return fTableSize;
- }
-
- inline OSErr THashList::Rehash()
- {
- return Grow(GetTableSize());
- }
-
- /*******************************************************************************
- ** CLASS THashListIterator
- ********************************************************************************/
-
- #define kTHashListIteratorID "!$hsit,1.1"
-
- class THashListIterator : public TIterator
- {
- public:
- MPWC THashListIterator(THashList*,
- TMatchObject* = NULL);
- virtual ~ MPWC THashListIterator();
-
- // TIterator Overrides
-
- virtual void MPWC Reset();
- virtual void* MPWC Next();
-
- virtual Boolean MPWC IterationComplete() const;
- virtual Boolean MPWC RemoveCurrentObject();
-
- protected:
- virtual Boolean MPWC SetNextTable(int);
-
- private:
- THashListIterator (const THashListIterator&);
- void operator=(const THashListIterator&);
-
- protected:
- THashList* fList;
- long fSeed;
- void** fTable;
- size_t fTableSize;
- TLink* fLink;
- size_t fCell;
- short fTableNo;
- Boolean fFirst;
- Boolean fComplete;
- };
-
- /*******************************************************************************
- ** CLASS TOperation
- *******************************************************************************/
-
- #define kTOperationID "!$oper,1.1"
-
- #define kRemovedInProcess ((TPriorityLink*)-1L)
-
- class TOperation : public TDynamic
- {
- public:
- MPWC TOperation();
- MPWC TOperation(long creatorData);
- MPWC TOperation(void* creatorPtr);
- MPWC TOperation(ProcessProcPtr, long creatorData);
- MPWC TOperation(ProcessProcPtr, void* creatorPtr);
- MPWC TOperation(const TOperation&);
- virtual ~ MPWC TOperation();
-
- TPriorityLink* GetLink();
-
- virtual void MPWC Reset();
- virtual void MPWC Process();
-
- Boolean WasRemovedInProcess() const;
- void ClearRemovedInProcess();
- void SetDeleteWhenDone();
- Boolean IsBeingRerun() const;
-
- void SetProcessProc(ProcessProcPtr);
- ProcessProcPtr GetProcessProc() const;
-
- // Timer and Priority are just 2 different ways
- // of looking at the same field.
-
- void SetTime(const TTime&);
- void SetTime(unsigned long msecs);
- void SetPriority(unsigned long pri);
- unsigned long GetTime() const;
- unsigned long GetPriority() const;
-
- // CreatorData and CreatorPtr are just 2 different ways
- // of looking at the same field.
-
- void* GetCreatorPtr() const;
- long GetCreatorData() const;
- void SetCreatorPtr(void*);
- void SetCreatorData(long);
-
- GlobalWorld GetSavedGlobalWorld() const;
- void SetSavedGlobalWorld(GlobalWorld);
-
- private:
-
- ProcessProcPtr fProc;
- union
- {
- void* fPtr;
- long fLong;
- } fCreatorData; // Storage for the Creator
- TPriorityLink fProcessLink;
- GlobalWorld fSavedWorld;
- };
-
- /* -----------------------------------------------------------------
- Inline Methods for TOperation
- ----------------------------------------------------------------- */
-
- inline TPriorityLink* TOperation::GetLink()
- {
- return &fProcessLink;
- }
-
- inline Boolean TOperation::WasRemovedInProcess() const
- {
- return fProcessLink.GetNext() == kRemovedInProcess;
- }
-
- inline void TOperation::ClearRemovedInProcess()
- {
- fProcessLink.SetNext(NULL);
- }
-
- inline Boolean TOperation::IsBeingRerun() const
- {
- return fProcessLink.GetPriority() != 0;
- }
-
- inline void TOperation::SetDeleteWhenDone()
- {
- fProcessLink.SetNext(kRemovedInProcess);
- }
-
- inline unsigned long TOperation::GetTime() const
- {
- return fProcessLink.GetPriority();
- }
-
- inline unsigned long TOperation::GetPriority() const
- {
- return fProcessLink.GetPriority();
- }
-
- inline void TOperation::SetTime(unsigned long msec)
- {
- fProcessLink.SetPriority(msec);
- }
-
- inline void TOperation::SetProcessProc(ProcessProcPtr proc)
- {
- fProc = proc;
- }
-
- inline void TOperation::SetPriority(unsigned long pri)
- {
- fProcessLink.SetPriority(pri);
- }
-
- inline void* TOperation::GetCreatorPtr() const
- {
- return fCreatorData.fPtr;
- }
-
- inline void TOperation::SetCreatorPtr(void* data)
- {
- fCreatorData.fPtr = data;
- }
-
- inline long TOperation::GetCreatorData() const
- {
- return fCreatorData.fLong;
- }
-
- inline void TOperation::SetCreatorData(long data)
- {
- fCreatorData.fLong = data;
- }
-
- inline ProcessProcPtr TOperation::GetProcessProc() const
- {
- return fProc;
- }
-
- inline GlobalWorld TOperation::GetSavedGlobalWorld() const
- {
- return fSavedWorld;
- }
-
- inline void TOperation::SetSavedGlobalWorld(GlobalWorld world)
- {
- fSavedWorld = world;
- }
-
- /*******************************************************************************
- ** CLASS TScheduler
- **
- ** This is the base class for all schedulers. It allows for scheduling
- ** TOperations and removing them from the scheduling queue.
- *******************************************************************************/
-
- #define kTSchedulerID "!$sked,1.1"
-
- class TScheduler : public TDynamic
- {
- protected:
- MPWC TScheduler();
-
- public:
- virtual ~ MPWC TScheduler();
-
- virtual Boolean MPWC Remove(TOperation*) = 0;
- virtual TOperation* MPWC Remove(const TMatchObject&) = 0;
- virtual TOperation* MPWC RemoveNext() = 0;
- virtual Boolean MPWC IsEmpty() const = 0;
-
- virtual void MPWC Schedule(TOperation*) = 0;
- virtual void MPWC Run() = 0;
-
- Boolean IsSchedulerWorldValid() const;
- GlobalWorld GetSchedulerWorld() const;
- void SetSchedulerWorld(GlobalWorld);
- protected:
- GlobalWorld fSchedulerWorld;
- };
-
- /* -------------------------------------------------------------------------
- Inline Methods for class TScheduler
- ------------------------------------------------------------------------- */
-
- inline Boolean TScheduler::IsSchedulerWorldValid() const
- {
- return fSchedulerWorld != kInvalidWorld;
- }
-
- inline GlobalWorld TScheduler::GetSchedulerWorld() const
- {
- return fSchedulerWorld;
- }
-
- inline void TScheduler::SetSchedulerWorld(GlobalWorld world)
- {
- fSchedulerWorld = world;
- }
-
- /*******************************************************************************
- ** CLASS TPriorityScheduler
- **
- ** This class implements a scheduler which simply insures processing
- ** of the TOperations by Priority.
- *******************************************************************************/
-
- #define kTPrioritySchedulerID "!$prsk,1.1"
-
- class TPriorityScheduler : public TScheduler
- {
- public:
- MPWC TPriorityScheduler(); // autoRun default to false
- MPWC TPriorityScheduler(BooleanParm ifAutoRun);
- virtual ~ MPWC TPriorityScheduler();
-
- virtual Boolean MPWC IsValid() const;
-
- // Returns non-zero if an Operation is removed
- virtual Boolean MPWC Remove(TOperation*);
- virtual TOperation* MPWC Remove(const TMatchObject&);
- virtual TOperation* MPWC RemoveNext();
- virtual Boolean MPWC IsEmpty() const;
-
- // Default implementation processes TOperations on the
- // linked list until it is empty, but insures that 2
- // threads are not doing it at the same time. In
- // Non-AutoRun mode, anything scheduled after "Run"
- // is called will not Run until "Run" is called again.
- virtual void MPWC Run();
-
- // Default implementation just throws the TOperation on
- // the linked list. If 'ifAutoRun' was set, the Run
- // method is called. Otherwise, someone must manually
- // call Run().
- virtual void MPWC Schedule(TOperation*);
-
- virtual void MPWC SetAutoRun(BooleanParm);
-
- protected:
- Boolean IsAutoRun() const;
- Boolean IsSchedulerDead() const;
- void SetSchedulerDead();
-
- TPriorityList fList;
- VOLATILE short fBusy;
- VOLATILE short fFlags;
- };
-
- /* -------------------------------------------------------------------------
- Inline methods for TPriorityScheduler
- ------------------------------------------------------------------------- */
-
- inline Boolean TPriorityScheduler::IsAutoRun() const
- {
- return fFlags & 1;
- }
-
- inline Boolean TPriorityScheduler::IsSchedulerDead() const
- {
- return fFlags < 0;
- }
-
- inline void TPriorityScheduler::SetSchedulerDead()
- {
- fFlags = -1;
- }
-
- /*******************************************************************************
- ** CLASS TSerialScheduler
- **
- ** This class implements a scheduler which simply insures FIFO processing
- ** of the TOperations. It is the same as a TPriorityScheduler, but
- ** sets the priority of the TOperation to kNormalPriority before
- ** scheduling.
- *******************************************************************************/
-
- #define kTSerialSchedulerID "!$srsk,1.1"
-
- class TSerialScheduler : public TPriorityScheduler
- {
- public:
- MPWC TSerialScheduler(); // autoRun default to false
- MPWC TSerialScheduler(BooleanParm ifAutoRun);
- virtual ~ MPWC TSerialScheduler();
-
- virtual void MPWC Schedule(TOperation*);
- };
-
- /*******************************************************************************
- ** CLASS TThreadScheduler
- **
- ** This class implements a lightweight 'thread' task. In the Macintosh
- ** implementation, it is a TPriorityScheduler.
- *******************************************************************************/
-
- #define kTThreadSchedulerID "slm:sked$thsk,1.1"
-
- class TThreadScheduler : public TPriorityScheduler
- {
- public:
-
- MPWC TThreadScheduler();
- virtual ~ MPWC TThreadScheduler();
-
- virtual void MPWC Schedule(TOperation*);
-
- protected:
- virtual void MPWC Run();
-
- private:
- void* fData;
- };
-
- /*******************************************************************************
- ** CLASS TTaskScheduler
- **
- ** This class implements a heavy-weight task which can interface to
- ** the operating system. In the Macintosh, it schedules TOperations to
- ** run at System Task time.
- *******************************************************************************/
-
- #define kTTaskSchedulerID "!$task,1.1"
-
- class TTaskScheduler : public TPriorityScheduler
- {
- public:
- MPWC TTaskScheduler();
- MPWC TTaskScheduler(unsigned long priority,
- BooleanParm runToEmpty = false);
- virtual ~ MPWC TTaskScheduler();
-
- virtual void MPWC Schedule(TOperation*);
-
- virtual void MPWC SetPriority(unsigned long);
- void MPWC SetRunToEmpty(Boolean);
-
- protected:
- void MPWC ProcessCalled();
-
- virtual void MPWC Run();
-
- private:
- void MPWC InitTaskScheduler(unsigned long);
-
- protected:
- TOperation fOperation;
-
- private:
- ProcPtr fSystem;
- void* fData;
- };
-
- /* -------------------------------------------------------------------------
- Inline methods for TTaskScheduler
- ------------------------------------------------------------------------- */
-
- inline void TTaskScheduler::SetRunToEmpty(Boolean runToEmpty)
- {
- SetAutoRun(runToEmpty);
- }
-
- /*******************************************************************************
- ** CLASS TInterruptScheduler
- **
- ** This class is used by all interrupt service routines to process
- ** incoming data. All layers above the interrupt service routines
- ** expect to be able to do any processing they want without fear of
- ** interrupts being locked out. That's what this scheduler insures.
- *******************************************************************************/
-
- #define kTInterruptSchedulerID "slm:sked$insk,1.1"
-
- class TInterruptScheduler : public TPriorityScheduler
- {
- public:
-
- MPWC TInterruptScheduler();
- MPWC TInterruptScheduler(TScheduler*, unsigned long priority);
- virtual ~ MPWC TInterruptScheduler();
-
- virtual Boolean MPWC IsValid() const;
-
- virtual void MPWC Schedule(TOperation*);
-
- protected:
- virtual void MPWC Run();
-
- private:
- void InitializeInterruptScheduler(TScheduler*, unsigned long);
- void* fData;
- };
-
- /*******************************************************************************
- ** CLASS TTimeScheduler
- **
- ** This class implements a scheduler which will process TOperations
- ** when a requested amount of time has expired.
- *******************************************************************************/
-
- #define kMaxScheduledTime ((unsigned long)-1L)
-
- #define kTTimeSchedulerID "slm:sked$skti,1.1"
-
- class TTimeScheduler : public TScheduler
- {
- public:
- MPWC TTimeScheduler();
- MPWC TTimeScheduler(void* data);
- MPWC TTimeScheduler(TScheduler*, unsigned long priority);
- virtual ~ MPWC TTimeScheduler();
-
- virtual Boolean MPWC IsValid() const;
-
- virtual Boolean MPWC Remove(TOperation*);
- virtual TOperation* MPWC Remove(const TMatchObject&);
- virtual TOperation* MPWC RemoveNext();
- virtual void MPWC Schedule(TOperation*);
- virtual Boolean MPWC IsEmpty() const;
-
- virtual Boolean MPWC Reschedule(TOperation*, unsigned long time);
- virtual void MPWC SetAutoReschedule(BooleanParm);
-
- virtual Boolean MPWC DeleteInProcessOperation(TOperation* op);
- virtual Boolean MPWC RerunInProcessOperation(TOperation* op);
-
- protected:
- virtual void MPWC Run();
- virtual unsigned long MPWC ProcessTimerEvent();
- virtual TOperation* MPWC PrivateRemove(TOperation*, const TMatchObject*);
- virtual TPriorityLink* MPWC GetNextOperation(void*);
- virtual void MPWC ProcessOperation();
- void* GetData() const;
-
- private:
- void MPWC InitializeTimeScheduler(TScheduler*, unsigned long);
-
- void* fData;
- short fTime;
- VOLATILE Boolean fDead;
- VOLATILE char fIfProcessing;
- TPriorityLink* fList;
- TSimpleList fReadyList;
-
- protected:
- VOLATILE long fSeed;
-
- private:
- VOLATILE Boolean fBusy;
- Boolean fFiller;
- };
-
- /* -------------------------------------------------------------------------
- Inline methods for TTimeScheduler
- ------------------------------------------------------------------------- */
-
- inline void* TTimeScheduler::GetData() const
- {
- return fData;
- }
-
-
- /*******************************************************************************
- ** CLASS TNotifier
- **
- ** This class and its subclasses are used for asynchronous notification
- ** of events.
- ********************************************************************************/
-
- #define kTNotifierID "!$noti,1.1"
-
- class TNotifier : public TDynamic
- {
- public:
- MPWC TNotifier();
- virtual ~ MPWC TNotifier();
-
- virtual void MPWC Notify(EventCode, OSErrParm = kNoError,
- void* = NULL) = 0;
-
- protected:
- GlobalWorld fWorld; // Global world when constructed.
- };
-
- /*******************************************************************************
- ** CLASS TProcNotifier
- **
- ** This class is the base class for Notifiers that call a "C" procedure
- ** for notification. If the "refPtr" is left NULL, it will be replaced
- ** with a pointer to the TProcNotifier itself.
- *******************************************************************************/
-
- #define kTProcNotifierID "!$pnot,1.1"
-
- class TProcNotifier : public TNotifier
- {
- public:
- MPWC TProcNotifier(NotifyProcPtr, void* refPtr = NULL);
- MPWC TProcNotifier(const TProcNotifier&);
- virtual ~ MPWC TProcNotifier();
-
- virtual void MPWC Notify(EventCode, OSErrParm = kNoError,
- void* notifyData = NULL);
-
- private:
- NotifyProcPtr fProc;
- void* fPtr;
- };
-
- /*******************************************************************************
- ** CLASS TMethodNotifier
- **
- ** This class is the base class for Notifiers that call a method in an object.
- *******************************************************************************/
-
- #define kTMethodNotifierID "!$mnot,1.1"
-
- class TMethodNotifier : public TNotifier
- {
- public:
- MPWC TMethodNotifier(TDynamic*, NotifyMethodPtr);
- MPWC TMethodNotifier(const TMethodNotifier&);
- virtual ~ MPWC TMethodNotifier();
-
- virtual void MPWC Notify(EventCode, OSErrParm = kNoError,
- void* notifyData = NULL);
-
- TDynamic* GetObject() const;
-
- private:
- TDynamic* fObject;
- NotifyMethodPtr fMethod;
- };
-
- /* -----------------------------------------------------------------
- Inlines for TMethodNotifier
- ----------------------------------------------------------------- */
-
- inline TDynamic* TMethodNotifier::GetObject() const
- {
- return fObject;
- }
-
- /*******************************************************************************
- ** CLASS TMemoryPool
- **
- ** This is the abstract class from which memory allocators should
- ** descend.
- ********************************************************************************/
-
- struct PoolInfo
- {
- size_t fFreeBytes;
- size_t fLargestBlock;
- size_t fMaxUsage;
- size_t fCurSize;
- };
-
- #define kTMemoryPoolID "!$pool,1.1"
-
- extern "C" void* NewPool(size_t, size_t, ZoneType, MemoryType);
- extern "C" void* NewPoolWithZone(size_t, size_t, void*, MemoryType);
- extern "C" void DeletePool(void*);
-
- class TMemoryPool : public TDynamic
- {
- public:
- virtual ~ MPWC TMemoryPool();
-
- void* operator new(size_t size, size_t poolSize, ZoneType zType,
- MemoryType mType = kNormalMemory)
- { return NewPool(size, poolSize, zType, mType); }
- void* operator new(size_t size, size_t poolSize, void* zone,
- MemoryType mType = kNormalMemory)
- { return NewPoolWithZone(size, poolSize, zone, mType); }
- void* operator new(size_t size)
- { return NewPool(size, 0, kCurrentZone, kNormalMemory); }
- void operator delete(void* ptr)
- { DeletePool(ptr); }
-
- virtual void* MPWC Allocate(size_t) = 0;
- virtual void* MPWC Reallocate(void*, size_t) = 0;
- virtual void MPWC Free(void*) = 0;
- virtual size_t MPWC GetSize(void*) const = 0;
-
- virtual Boolean MPWC CheckPool() const = 0;
- virtual void MPWC GetPoolInfo(PoolInfo&) const;
- virtual void MPWC TracePoolInfo() const;
-
- virtual Boolean MPWC AddMemoryToPool(size_t);
- virtual void MPWC DownsizePool();
- virtual size_t MPWC GetLargestBlockSize() const = 0;
- size_t MPWC GetCurrentPoolSize() const;
-
- void SetNotifier(TPoolNotifier*);
- TPoolNotifier* GetNotifier() const;
- void SetNotifyMarks(size_t low, size_t high = (size_t)-1L);
-
- static TMemoryPool* MPWC RecoverPool(void*);
- static void* MPWC AllocateMemory(size_t);
- static void* MPWC AllocateMemory(TMemoryPool*, size_t);
- static void* MPWC ReallocateMemory(void*, size_t);
- static void MPWC FreeMemory(void*);
- static size_t MPWC GetMemorySize(void*);
-
- protected:
- MPWC TMemoryPool();
- virtual Boolean MPWC PrivateAddMemoryToPool(void*, size_t) = 0;
- virtual Boolean MPWC RemoveBlockFromPool(void*, size_t);
-
- private:
- TMemoryPool(const TMemoryPool&);
- void operator=(const TMemoryPool&);
-
- private:
- void* fMemList;
-
- protected:
- size_t fSize;
- size_t fLowMark;
- size_t fHighMark;
- size_t fMaxUsed;
- size_t fCurFree;
- void* fZone;
- unsigned char fMemType;
- short fFiller;
- TPoolNotifier* fNotifier;
- unsigned long fSeed;
- TMacSemaphore fSemaphore;
- };
-
- /* -----------------------------------------------------------------
- Inline Methods for TMemoryPool
- ----------------------------------------------------------------- */
-
- inline void TMemoryPool::SetNotifyMarks(size_t low, size_t high)
- {
- fLowMark = low;
- fHighMark= high;
- }
-
- inline TPoolNotifier* TMemoryPool::GetNotifier() const
- {
- return fNotifier;
- }
-
- inline void TMemoryPool::SetNotifier(TPoolNotifier* nt)
- {
- fNotifier = nt;
- }
-
- inline size_t TMemoryPool::GetCurrentPoolSize() const
- {
- return fSize;
- }
-
- inline void* TMemoryPool::AllocateMemory(TMemoryPool* thePool, size_t size)
- {
- return thePool->Allocate(size);
- }
-
- inline void* TMemoryPool::AllocateMemory(size_t size)
- {
- return ((TMemoryPool*)::GetDefaultPool())->Allocate(size);
- }
-
- /*******************************************************************************
- ** CLASS TStandardPool
- **
- ** The general purpose interrupt capable storage allocator.
- ********************************************************************************/
-
- #define kStandardPoolChunkOverhead 12
-
- #define kTStandardPoolID "!$stdp,1.1"
-
- class TStandardPool : public TMemoryPool
- {
- public:
- MPWC TStandardPool();
- virtual ~ MPWC TStandardPool();
-
- virtual Boolean MPWC IsValid() const;
-
- // TMemoryPool Overrides
-
- virtual void* MPWC Allocate(size_t);
- virtual void* MPWC Reallocate(void*, size_t);
- virtual void MPWC Free(void*);
- virtual size_t MPWC GetSize(void*) const;
- virtual Boolean MPWC CheckPool() const;
- virtual size_t MPWC GetLargestBlockSize() const;
-
- protected:
- virtual Boolean MPWC PrivateAddMemoryToPool(void*, size_t);
- virtual Boolean MPWC RemoveBlockFromPool(void*, size_t);
-
- MPWC TStandardPool(size_t objSize);
-
- private:
- TStandardPool(const TStandardPool&);
- void operator=(const TStandardPool&);
-
- void MPWC InitStandardPool(size_t objSize);
-
- Boolean FreeChunks(void*, size_t);
- void InternalFree(void*);
-
- protected:
- void* fList;
-
- private:
- void* fChunks[12];
- };
-
-
- /*******************************************************************************
- ** CLASS TChunkyPool
- **
- ** This class implements a Pool where the memory returned is always
- ** the same size (a "chunk").
- ********************************************************************************/
-
- #define kChunkyPoolChunkOverhead 4
-
- #define kTChunkyPoolID "!$chkp,1.1"
-
- class TChunkyPool : public TMemoryPool
- {
- public:
- MPWC TChunkyPool(size_t chunkSize);
- virtual ~ MPWC TChunkyPool();
-
- virtual Boolean MPWC IsValid() const;
-
- // TMemoryPool Overrides
-
- virtual void* MPWC Allocate(size_t size);
- virtual void* MPWC Reallocate(void*, size_t);
- virtual void MPWC Free(void*);
- virtual size_t MPWC GetSize(void*) const;
- virtual Boolean MPWC CheckPool() const;
- virtual size_t MPWC GetLargestBlockSize() const;
-
- protected:
- virtual Boolean MPWC PrivateAddMemoryToPool(void*, size_t);
- virtual Boolean MPWC RemoveBlockFromPool(void*, size_t);
-
- public:
- // New methods
-
- size_t GetChunkSize() const;
- size_t GetNumberOfChunks() const;
-
- private:
- TChunkyPool(const TChunkyPool&);
- void operator=(const TChunkyPool&);
-
- size_t fNumberOfChunks;
- size_t fChunkSize;
- void* fFreeList;
- };
-
- /* -----------------------------------------------------------------
- Inline Methods for TChunkyPool
- ----------------------------------------------------------------- */
-
- inline size_t TChunkyPool::GetChunkSize() const
- {
- return fChunkSize;
- }
-
- inline size_t TChunkyPool::GetNumberOfChunks() const
- {
- return fNumberOfChunks;
- }
-
- /*******************************************************************************
- ** CLASS TGrowOperation
- **
- ** See TPoolNotifier below
- ********************************************************************************/
-
- #define kTGrowOperationID "!$gwop,1.1"
-
- class TGrowOperation : public TOperation
- {
- public:
- MPWC TGrowOperation();
- virtual ~ MPWC TGrowOperation();
-
- virtual void MPWC Process();
-
- size_t fGrowBy;
- Boolean* fOpInUse;
- };
-
- /*******************************************************************************
- ** CLASS TPoolNotifier
- **
- ** Used by TMemoryPools so they can be notified when the pool reaches a low or
- ** high water mark. The TGrowOperation is not processed at interrupt time so it
- ** is always safe for it to grow the pool.
- ********************************************************************************/
-
- #define kTPoolNotifierID "!$plnt,1.1"
-
- class TPoolNotifier : public TNotifier
- {
- public:
- MPWC TPoolNotifier(unsigned int growBy = 10,
- unsigned int minGrow = 128);
- virtual ~ MPWC TPoolNotifier();
-
- virtual void MPWC Notify(EventCode, OSErrParm = kNoError, void* = NULL);
- virtual size_t MPWC GrowBy(TMemoryPool*, size_t);
-
- private:
- void MPWC InitNotifier(unsigned int, unsigned int);
-
- TGrowOperation fOperation;
- unsigned short fMinSize;
- unsigned short fGrowBy;
- Boolean fOpInUse;
- Boolean fFiller;
- };
-
- /*******************************************************************************
- ** CLASS TArbitrator
- *******************************************************************************/
-
- #define kTArbitratorID "!$arbt,1.1"
-
- #define kRequestIDPrefix '?'
- #define kRequestIDPrefixSize 1
-
- typedef int TokenRequestType;
-
- #define kInvalidTokenRequest ((TokenRequestType)0)
- #define kRequestTokenRequest ((TokenRequestType)1)
- #define kExclusiveTokenRequest ((TokenRequestType)2)
- #define kSharedTokenRequest ((TokenRequestType)3)
-
- class TArbitrator : public THashObject
- {
- friend class TToken;
- public:
- MPWC TArbitrator(TStandardPool* = NULL,
- size_t defSize = 0);
- virtual ~ MPWC TArbitrator();
-
- virtual OSErr MPWC RegisterObject(const char* theID, void* theObject);
- virtual void* MPWC UnregisterObject(const char* theID);
- virtual void* MPWC LookupObject(const char* theID);
-
- virtual OSErr MPWC RegisterToken(TToken*);
- virtual TToken* MPWC GetToken(const char* theID, TokenRequestType);
-
- virtual TRequestToken* MPWC PassiveRequest(const char* theID, TokenRequestType,
- TNotifier* = NULL,
- BooleanParm registerIfFirst = false);
- virtual TRequestToken* MPWC ActiveRequest(const char* theID, TokenRequestType,
- TNotifier* = NULL,
- BooleanParm registerIfFirst = false);
- virtual TRequestToken* MPWC GetRequest(const char* theID);
-
- virtual Boolean MPWC NotifyOwners(TRequestToken* theRequest);
- virtual unsigned long MPWC Hash(const void*) const;
-
- virtual TToken* MPWC NewToken(const char* theID, void* = NULL);
-
- private: // methods
- virtual void MPWC ReleaseToken(TToken* theToken);
- virtual TRequestToken* MPWC NewRequestToken(const char* theID, TokenRequestType,
- TNotifier* = NULL);
- public:
- virtual void MPWC UnregisterToken(TToken*);
-
- private: // data
- TCollection* fHashList;
- };
-
- /*******************************************************************************
- ** Class TTokenNotification (inline methods only)
- *******************************************************************************/
-
- class TTokenNotification
- {
- public:
- MPWC TTokenNotification(TToken*, TRequestToken*);
- ~ MPWC TTokenNotification();
- TToken* GetToken();
- TRequestToken* GetRequestToken();
- private:
- TToken* fToken;
- TRequestToken* fRequestToken;
- };
-
- /* -----------------------------------------------------------------
- inline methods for TTokenNotification
- ----------------------------------------------------------------- */
-
- inline TToken* TTokenNotification::GetToken()
- {
- return fToken;
- }
-
- inline TRequestToken* TTokenNotification::GetRequestToken()
- {
- return fRequestToken;
- }
-
-
- /*******************************************************************************
- ** CLASS TToken
- *******************************************************************************/
-
- #define kTTokenID "!$tokn,1.1"
-
- class TToken : public TMatchObject
- {
- friend class TArbitrator;
-
- public:
- MPWC TToken();
- MPWC TToken(const char*);
- virtual ~ MPWC TToken();
-
- // TMatchObject methods
-
- virtual Boolean MPWC IsEqual(const void*) const;
- virtual unsigned long MPWC Hash() const;
-
- // new methods
-
- virtual Boolean MPWC Get(TokenRequestType);
- virtual void MPWC Release();
- virtual Boolean MPWC Request(TRequestToken*);
- virtual Boolean MPWC Notify(TRequestToken*);
- virtual TokenRequestType MPWC GetRequestType() const;
-
- virtual void MPWC SetID(const char*);
- const char* GetID() const;
-
- void* GetObject() const;
- void SetObject(void* theObject);
-
- TNotifier* GetNotifier() const;
- void SetNotifier(TNotifier*);
-
- long GetUseCount() const;
-
- private:
- virtual void MPWC ReallyRelease();
-
- protected:
- TMacSemaphore fSemaphore;
- char* fID;
- void* fObject;
- TArbitrator* fArbitrator;
- long fUseCount;
- TNotifier* fNotifier;
- };
-
- /* -----------------------------------------------------------------
- inlines for TToken
- ----------------------------------------------------------------- */
-
- inline const char* TToken::GetID() const
- {
- return fID;
- }
-
- inline void* TToken::GetObject() const
- {
- return fObject;
- }
-
- inline void TToken::SetObject(void* theObject)
- {
- fObject = theObject;
- }
-
- inline TNotifier* TToken::GetNotifier() const
- {
- return fNotifier;
- }
-
- inline void TToken::SetNotifier(TNotifier* theNotifier)
- {
- fNotifier = theNotifier;
- }
-
- inline long TToken::GetUseCount() const
- {
- return fUseCount;
- }
-
- /*******************************************************************************
- ** CLASS TRequestToken
- *******************************************************************************/
-
- #define kTRequestTokenID "!$rqtk,1.1"
-
- class TRequestToken : public TToken
- {
- friend class TArbitrator;
-
- public:
- virtual ~ MPWC TRequestToken();
-
- // TMatchObject methods
-
- virtual Boolean MPWC IsEqual(const void*) const;
- virtual unsigned long MPWC Hash() const;
-
- // new methods
-
- virtual Boolean MPWC Give(TToken* theToken);
- virtual TToken* MPWC Exchange();
- virtual void MPWC RequestAgain();
-
- virtual TokenRequestType MPWC GetRequestType() const;
- virtual void MPWC SetRequestType(TokenRequestType);
-
- Boolean IsTokenRegistered() const;
-
- private:
- MPWC TRequestToken();
-
- private: // data
- Boolean fTokenRegistered;
- Boolean fActive;
- TokenRequestType fRequestType;
- };
-
- /* -----------------------------------------------------------------
- inlines for TRequestToken
- ----------------------------------------------------------------- */
-
- inline Boolean TRequestToken::IsTokenRegistered() const
- {
- return fTokenRegistered;
- }
-
-
- /*******************************************************************************
- ** class TClassInfo
- ********************************************************************************/
-
- #define kTClassInfoID "slm:supp$clif,1.1"
-
- class TClassInfo : public TIterator
- {
- friend class TLibraryManager;
-
- public:
- virtual ~ MPWC TClassInfo();
-
- // TIterator overrides
-
- virtual void MPWC Reset();
- virtual void* MPWC Next(); // safe to cast to TClassID* or char*
-
- virtual Boolean MPWC IterationComplete() const;
- virtual Boolean MPWC RemoveCurrentObject(); // do nothing instead
-
- // new methods
-
- void SetBaseClassID(const TClassID& classID);
-
- TClassID* GetClassID();
- virtual TClassID* MPWC GetParentID(size_t idx = 0);
- TLibrary* GetLibrary() const;
- TLibraryFile* GetLibraryFile() const;
- unsigned short GetVersion() const;
- unsigned short GetMinVersion() const;
-
- Boolean GetNewObjectFlag() const;
- Boolean GetPreloadFlag() const;
- Boolean GetFunctionSetFlag() const;
- size_t GetSize() const;
-
- private:
- MPWC TClassInfo();
-
- private:
- TClassID fBaseClassID;
- TClassID fClassID;
- TLibrary* fLibrary;
- TLibraryFile* fLibraryFile;
- unsigned short fVersion; // Class version
- unsigned short fMinVersion; // minimum supported version
- Boolean fNewObjectFlag;
- Boolean fPreloadFlag;
- Boolean fFunctionSetFlag;
- Boolean fFiller;
- size_t fSize;
- TClassID fParentID;
- };
-
- /* -------------------------------------------------------------------------
- inline methods of TClassInfo
- ------------------------------------------------------------------------- */
-
- inline void TClassInfo::SetBaseClassID(const TClassID& classID)
- {
- fBaseClassID = classID;
- Reset();
- }
-
- inline TClassID* TClassInfo::GetClassID()
- {
- return &fClassID;
- }
-
- inline TLibrary* TClassInfo::GetLibrary() const
- {
- return fLibrary;
- }
-
- inline TLibraryFile* TClassInfo::GetLibraryFile() const
- {
- return fLibraryFile;
- }
-
- inline unsigned short TClassInfo::GetVersion() const
- {
- return fVersion;
- }
-
- inline unsigned short TClassInfo::GetMinVersion() const
- {
- return fMinVersion;
- }
-
- inline Boolean TClassInfo::GetNewObjectFlag() const
- {
- return fNewObjectFlag;
- }
-
- inline Boolean TClassInfo::GetPreloadFlag() const
- {
- return fPreloadFlag;
- }
-
- inline Boolean TClassInfo::GetFunctionSetFlag() const
- {
- return fFunctionSetFlag;
- }
-
- inline size_t TClassInfo::GetSize() const
- {
- return fSize;
- }
-
- /**********************************************************************
- ** class TFileSpec
- **
- ** TFileSpec is a base class for specifying the location of a library
- ** file (TLibraryFile) in a file system or OS independent way. The
- ** subclasses contain the details and the base class is used to compare
- ** them or to pass them around without worry about the contents.
- **
- ** Currently only the TMacFileSpec is supported since this is how the
- ** SLM tracks library files on the Mac OS. There is a chance that in the
- ** furture it may track files under System 7.0 using TFileIDFileSpec so
- ** you should write your 7.0 code to handle either type. The
- ** IsFileSpecTypeSupported() routine will tell you if the specified
- ** TFileSpec subclass is supported.
- **
- ** Generally you don't need to be concerned with with TFileSpecs unless
- ** you are going to call RegisterLibraryFile(), RegisterLibraryFileFolder(),
- ** or TLibraryFile::GetFileSpec().
- ***********************************************************************/
-
- // Different types of TFileSpecs we can have.
- typedef unsigned int FileSpecType;
-
- #define kUnknownFileSpecType ((FileSpecType)0)
- #define kMacType ((FileSpecType)1)
- #define kFileIDType ((FileSpecType)2)
- #define kMaxFileSpecType ((FileSpecType)255)
-
- class TFileSpec;
- class TMacFileSpec;
- class TFileIDFileSpec;
-
- extern "C" Boolean IsFileSpecTypeSupported(FileSpecType);
- extern "C" Boolean CompareFileSpecs(const void* f1, const void* f2);
-
- class TFileSpec
- {
- public:
- void* operator new(size_t size, TMemoryPool *thePool)
- { return SLMNewOperator(size, thePool); }
- void* operator new(size_t size)
- { return SLMNewOperator(size, NULL); }
- void operator delete(void* obj, size_t)
- { SLMDeleteOperator(obj); }
-
- FileSpecType GetType() const;
- unsigned char GetSize() const;
-
- // compare operators
-
- Boolean operator==(const TFileSpec&) const;
- Boolean operator!=(const TFileSpec&) const;
-
- // cast operators
-
- operator const TMacFileSpec&() const;
- operator const TFileIDFileSpec&() const;
-
- unsigned char fType;
- unsigned char fSize;
- };
-
- inline FileSpecType TFileSpec::GetType() const
- {
- return fType;
- }
-
- inline unsigned char TFileSpec::GetSize() const
- {
- return fSize;
- }
-
- //
- // compare operators
- //
-
- inline Boolean TFileSpec::operator==(const TFileSpec& fileSpec) const
- {
- return (CompareFileSpecs(&fileSpec, this));
- }
-
- inline Boolean TFileSpec::operator!=(const TFileSpec& fileSpec) const
- {
- return (!CompareFileSpecs(&fileSpec, this));
- }
-
- //
- // cast operators
- //
-
- inline TFileSpec::operator const TMacFileSpec&() const
- {
- return *(const TMacFileSpec*)this;
- }
-
- inline TFileSpec::operator const TFileIDFileSpec&() const
- {
- return *(const TFileIDFileSpec*)this;
- }
-
-
- /**********************************************************************
- ** class TMacFileSpec
- **
- ** TMacFileSpec keeps track of the file by using an file name, volume
- ** refNum, and directory id. When newing a TMacFileSpec, you must
- ** pass the length of the file name (not including the length byte)
- ** to the new operator.
- ***********************************************************************/
-
- extern "C" void InitMacFileSpec(TMacFileSpec *spec, int vRefNum, long parID, Str63 name);
-
- class TMacFileSpec : public TFileSpec
- {
- public:
- TMacFileSpec(const TMacFileSpec&);
- TMacFileSpec(int vRefNum, long parID, Str63 name);
-
- void* operator new(size_t, size_t fileNameLen, TMemoryPool *thePool = NULL)
- {
- return SLMNewOperator(
- (sizeof(TMacFileSpec) -
- sizeof(Str63) +
- fileNameLen+1), thePool);
- }
- void* operator new(size_t size)
- { return SLMNewOperator(size, NULL); }
-
- void operator delete(void* obj)
- { SLMDeleteOperator(obj); }
-
- short fVRefNum; // volume refNum of volume file is on
- long fParID; // dirID of the folder file is in
- Str63 fName; // name of the file
- };
-
- inline TMacFileSpec::TMacFileSpec(const TMacFileSpec& fileSpec)
- {
- InitMacFileSpec(this, fileSpec.fVRefNum, fileSpec.fParID, fileSpec.fName );
- }
-
- inline TMacFileSpec::TMacFileSpec(int vRefNum, long parID, Str63 name)
- {
- InitMacFileSpec(this, vRefNum, parID, name);
- }
-
-
- /**********************************************************************
- ** class TFileIDFileSpec
- **
- ** TFileIDFileSpec keeps track of library files by fileID and vRefNum.
- ***********************************************************************/
-
- // Some macros to make accessing fields without doing a cast easier
- #define GetFileIDFromFileSpec(x) (((const TFileIDFileSpec&)x).fFileID)
- #define GetVRefNumFromFileSpec(x) (((const TFileIDFileSpec&)x).fVRefNum)
-
- extern "C" void InitFileIDFileSpec(TFileIDFileSpec *spec, int vRefNum, long fileID);
-
- class TFileIDFileSpec : public TFileSpec
- {
- public:
- TFileIDFileSpec(const TFileIDFileSpec&);
- TFileIDFileSpec(int vRefNum, long fileID);
-
- short fVRefNum; // volume refNum
- long fFileID; // FileID
- };
-
- inline TFileIDFileSpec::TFileIDFileSpec(const TFileIDFileSpec& fileSpec)
- {
- InitFileIDFileSpec(this, GetVRefNumFromFileSpec(fileSpec),
- GetFileIDFromFileSpec(fileSpec));
- }
-
- inline TFileIDFileSpec::TFileIDFileSpec(int vRefNum, long fileID)
- {
- InitFileIDFileSpec(this, vRefNum, fileID);
- }
-
- /*******************************************************************************
- ** Class TLibraryFile
- **
- ** Used mainly to get resources out of a library file. A "C" interface is also
- ** provided in TLibraryManagerUtilities.h
- *******************************************************************************/
-
- #define kTLibraryFileID "!$lfil,1.1"
-
- extern "C" TLibraryFile* GetLocalLibraryFile();
-
- class TLibraryFile : public TDynamic
- {
- protected:
- virtual ~ MPWC TLibraryFile();
- MPWC TLibraryFile();
-
- // This is the old prelight/postflight that we need to keep around so 1.0
- // clients will still work. SLM 1.1 clients should never call it. Use the
- // new calls further below
-
- virtual OSErr MPWC OldPreflight(short& savedRefNum) = 0;
- virtual OSErr MPWC OldPostflight(short savedRefNum) = 0;
-
- public:
- virtual Ptr MPWC GetSharedResource(ResType, int theID, OSErr* = NULL) = 0;
- virtual Ptr MPWC GetSharedIndResource(ResType, int index, OSErr* = NULL) = 0;
- virtual Ptr MPWC GetSharedNamedResource(ResType, const char* name,
- OSErr* = NULL) = 0;
-
- virtual void MPWC ReleaseSharedResource(Ptr) = 0;
- virtual long MPWC CountSharedResources(ResType) = 0;
-
- virtual size_t MPWC GetSharedResourceUseCount(Ptr) const = 0;
- virtual OSErr MPWC GetSharedResourceInfo(Ptr, size_t* theSize = NULL,
- short* theID = NULL, ResType* = NULL,
- char* theName = NULL) const = 0;
-
- virtual long MPWC GetRefNum() const = 0;
- virtual TFileSpec* MPWC GetFileSpec() const = 0;
-
- virtual OSErr MPWC OpenLibraryFile() = 0;
- virtual OSErr MPWC CloseLibraryFile() = 0;
-
- virtual OSErr MPWC Preflight(long& savedRefNum) = 0;
- virtual OSErr MPWC Postflight(long savedRefNum) = 0;
- };
-
- /*******************************************************************************
- ** CLASS TBitmap
- *******************************************************************************/
-
- #define kTBitmapID "slm:supp$bmap,1.1"
-
- class TBitmap : public TDynamic
- {
- public:
- MPWC TBitmap(size_t numBits, TMemoryPool* pool);
- MPWC TBitmap(void* bits, size_t nBits);
- virtual ~ MPWC TBitmap();
-
- virtual Boolean MPWC IsValid() const;
-
- // NOTE: There is no ErrorChecking on these first 3 calls.
-
- virtual Boolean MPWC SetBit(size_t);
- virtual Boolean MPWC ClearBit(size_t);
- virtual Boolean MPWC TestBit(size_t);
-
- // These return -1 if no free bits
-
- virtual long MPWC SetFirstClearBit();
- virtual long MPWC SetFirstClearBit(size_t, size_t);
-
- private:
- void InitBitmap(size_t numBits, TMemoryPool* pool);
- void InitBitmap(void* bits, size_t nBits);
-
- unsigned char* fBits;
- size_t fNumberBits;
- Boolean fIsNewd;
- Boolean fFiller;
- };
-
- /*******************************************************************************
- ** CLASS TFastRandom
- ********************************************************************************/
-
- #define kTFastRandomID "slm:supp$frnd,1.1"
-
- const unsigned long kMaxFastRandom = 1771874;
-
- class TFastRandom : public TDynamic
- {
- public:
- MPWC TFastRandom();
- MPWC TFastRandom(unsigned long seed);
- virtual ~ MPWC TFastRandom();
-
- virtual void MPWC SetSeed(unsigned long seed);
- virtual void MPWC SetSeed();
- unsigned long GetSeed() const;
-
- virtual unsigned long MPWC GetRandom();
- virtual unsigned long MPWC GetRandomNumber(unsigned long lo,
- unsigned long hi);
-
- protected:
- unsigned long fSeed;
- };
-
- /* -------------------------------------------------------------------------
- Inline method for TFastRandom
- ------------------------------------------------------------------------- */
-
- inline unsigned long TFastRandom::GetSeed() const
- {
- return fSeed;
- }
-
- /*******************************************************************************
- ** CLASS TSimpleRandom
- ********************************************************************************/
-
- #define kTSimpleRandomID "slm:supp$srnd,1.1"
-
- const unsigned long kMaxSimpleRandom = 2145740624;
-
- class TSimpleRandom : public TFastRandom
- {
- public:
- MPWC TSimpleRandom();
- MPWC TSimpleRandom(unsigned long seed);
- MPWC TSimpleRandom(unsigned long im, unsigned long ia,
- unsigned long ic);
- virtual ~ MPWC TSimpleRandom();
-
- virtual unsigned long MPWC GetRandom();
- virtual unsigned long MPWC GetRandomNumber(unsigned long lo,
- unsigned long hi);
-
- protected:
- unsigned long fIM;
- unsigned long fIA;
- unsigned long fIC;
- };
-
- /*******************************************************************************
- ** CLASS TDoubleLong
- **
- ** Implements a TDynamic double long (64 bits). Normally this is used
- ** as a superclass for some other class which has a 64-bit value as its
- ** comparable/hashing value (the default hash value is the low 32-bits).
- *******************************************************************************/
-
- #define kTDoubleLongID "slm:supp$dbll,1.1"
-
- class TDoubleLong : public TMatchObject
- {
- public:
- MPWC TDoubleLong(const TDoubleLong&);
- MPWC TDoubleLong(unsigned long low, long hi);
- MPWC TDoubleLong(long l);
- MPWC TDoubleLong();
- virtual ~ MPWC TDoubleLong();
-
- virtual OSErr MPWC Inflate(TFormattedStream&);
- virtual OSErr MPWC Flatten(TFormattedStream&) const;
-
- virtual Boolean MPWC IsEqual(const void*) const;
- virtual unsigned long MPWC Hash() const;
-
- virtual double MPWC ConvertToDouble() const;
- operator double() const;
- operator unsigned long() const;
-
- virtual TDoubleLong& MPWC Add(const TDoubleLong&);
- virtual TDoubleLong& MPWC Subtract(const TDoubleLong&);
- virtual TDoubleLong& MPWC Multiply(const TDoubleLong&);
- virtual TDoubleLong& MPWC Divide(const TDoubleLong&);
- virtual TDoubleLong& MPWC Modulo(const TDoubleLong&);
- virtual TDoubleLong MPWC RShift(unsigned int) const;
- virtual TDoubleLong MPWC LShift(unsigned int) const;
- virtual TDoubleLong& MPWC Negate();
- virtual short MPWC Compare(const void*) const;
-
- TDoubleLong& operator=(const TDoubleLong&);
- TDoubleLong& operator+=(const TDoubleLong&);
- TDoubleLong& operator-=(const TDoubleLong&);
- TDoubleLong& operator*=(const TDoubleLong&);
- TDoubleLong& operator/=(const TDoubleLong&);
- TDoubleLong& operator%=(const TDoubleLong&);
- TDoubleLong& operator&=(const TDoubleLong&);
- TDoubleLong& operator|=(const TDoubleLong&);
- TDoubleLong& operator^=(const TDoubleLong&);
-
- TDoubleLong operator+(const TDoubleLong&) const;
- TDoubleLong operator-(const TDoubleLong&) const;
- TDoubleLong operator*(const TDoubleLong&) const;
- TDoubleLong operator/(const TDoubleLong&) const;
- TDoubleLong operator%(const TDoubleLong&) const;
- TDoubleLong operator&(const TDoubleLong&) const;
- TDoubleLong operator|(const TDoubleLong&) const;
- TDoubleLong operator^(const TDoubleLong&) const;
- TDoubleLong operator~() const;
- TDoubleLong operator-() const;
-
- TDoubleLong operator<<(unsigned int) const;
- TDoubleLong operator>>(unsigned int) const;
-
- Boolean operator>(const TDoubleLong&) const;
- Boolean operator<(const TDoubleLong&) const;
- Boolean operator<=(const TDoubleLong&) const;
- Boolean operator>=(const TDoubleLong&) const;
- Boolean operator==(const TDoubleLong&) const;
- Boolean operator!=(const TDoubleLong&) const;
-
- protected:
- long fHiBits;
- unsigned long fLoBits;
- };
-
- /* -----------------------------------------------------------------
- Inline Methods for TDoubleLong
- ----------------------------------------------------------------- */
-
- inline TDoubleLong::operator unsigned long() const
- {
- return fLoBits;
- }
-
- inline TDoubleLong::operator double() const
- {
- return ConvertToDouble();
- }
-
- inline TDoubleLong TDoubleLong::operator &(const TDoubleLong& val) const
- {
- return TDoubleLong(fLoBits & val.fLoBits, fHiBits & val.fHiBits);
- }
-
- inline TDoubleLong& TDoubleLong::operator =(const TDoubleLong& val)
- {
- fHiBits = val.fHiBits;
- fLoBits = val.fLoBits;
- return *this;
- }
-
- inline TDoubleLong& TDoubleLong::operator +=(const TDoubleLong& val)
- {
- return Add(val);
- }
-
- inline TDoubleLong& TDoubleLong::operator -=(const TDoubleLong& val)
- {
- return Subtract(val);
- }
-
- inline TDoubleLong& TDoubleLong::operator *=(const TDoubleLong& val)
- {
- return Multiply(val);
- }
-
- inline TDoubleLong& TDoubleLong::operator /=(const TDoubleLong& val)
- {
- return Divide(val);
- }
-
- inline TDoubleLong& TDoubleLong::operator %=(const TDoubleLong& val)
- {
- return Modulo(val);
- }
-
- inline TDoubleLong& TDoubleLong::operator &=(const TDoubleLong& val)
- {
- fHiBits &= val.fHiBits;
- fLoBits &= val.fLoBits;
- return *this;
- }
-
- inline TDoubleLong& TDoubleLong::operator |=(const TDoubleLong& val)
- {
- fHiBits |= val.fHiBits;
- fLoBits |= val.fLoBits;
- return *this;
- }
-
- inline TDoubleLong& TDoubleLong::operator ^=(const TDoubleLong& val)
- {
- fHiBits ^= val.fHiBits;
- fLoBits ^= val.fLoBits;
- return *this;
- }
-
- inline TDoubleLong TDoubleLong::operator +(const TDoubleLong& val) const
- {
- TDoubleLong temp(*this);
- (&temp)->Add(val);
- return temp;
- }
-
- inline TDoubleLong TDoubleLong::operator -(const TDoubleLong& val) const
- {
- TDoubleLong temp(*this);
- (&temp)->Subtract(val);
- return temp;
- }
-
- inline TDoubleLong TDoubleLong::operator *(const TDoubleLong& val) const
- {
- TDoubleLong temp(*this);
- (&temp)->Multiply(val);
- return temp;
- }
-
- inline TDoubleLong TDoubleLong::operator /(const TDoubleLong& val) const
- {
- TDoubleLong temp(*this);
- (&temp)->Divide(val);
- return temp;
- }
-
- inline TDoubleLong TDoubleLong::operator %(const TDoubleLong& val) const
- {
- TDoubleLong temp(*this);
- (&temp)->Modulo(val);
- return temp;
- }
-
- inline TDoubleLong TDoubleLong::operator |(const TDoubleLong& val) const
- {
- return TDoubleLong(fLoBits | val.fLoBits, fHiBits | val.fHiBits);
- }
-
- inline TDoubleLong TDoubleLong::operator ^(const TDoubleLong& val) const
- {
- return TDoubleLong(fLoBits ^ val.fLoBits, fHiBits ^ val.fHiBits);
- }
-
- inline TDoubleLong TDoubleLong::operator~() const
- {
- return TDoubleLong(~fLoBits, ~fHiBits);
- }
-
- inline TDoubleLong TDoubleLong::operator -() const
- {
- TDoubleLong temp(*this);
- (&temp)->Negate();
- return temp;
- }
-
- inline TDoubleLong TDoubleLong::operator >>(unsigned int val) const
- {
- return RShift(val);
- }
-
- inline TDoubleLong TDoubleLong::operator <<(unsigned int val) const
- {
- return LShift(val);
- }
-
- inline Boolean TDoubleLong::operator ==(const TDoubleLong& val) const
- {
- return fLoBits == val.fLoBits && fHiBits == val.fHiBits;
- }
-
- inline Boolean TDoubleLong::operator !=(const TDoubleLong& val) const
- {
- return fLoBits != val.fLoBits || fHiBits != val.fHiBits;
- }
-
- inline Boolean TDoubleLong::operator >(const TDoubleLong& val) const
- {
- return Compare(&val) > 0;
- }
-
- inline Boolean TDoubleLong::operator >=(const TDoubleLong& val) const
- {
- return Compare(&val) >= 0;
- }
-
- inline Boolean TDoubleLong::operator <(const TDoubleLong& val) const
- {
- return Compare(&val) < 0;
- }
-
- inline Boolean TDoubleLong::operator <=(const TDoubleLong& val) const
- {
- return Compare(&val) <= 0;
- }
-
- /*******************************************************************************
- ** CLASS THashDoubleLong
- **
- ** Class to hash a TDoubleLong. The 'const void*' parameter is a
- ** pointer to a TDoubleLong object.
- *******************************************************************************/
-
- #define kTHashDoubleLongID "slm:supp$hdbl,1.1"
-
- class THashDoubleLong : public THashObject
- {
- public:
- MPWC THashDoubleLong();
- virtual ~ MPWC THashDoubleLong();
-
- virtual unsigned long MPWC Hash(const void*) const;
- };
-
- /*******************************************************************************
- ** CLASS TTime
- **
- ** This is the superclass for all Time-related classes. Internally,
- ** all times are stored as microSeconds, and the casting operators
- ** for the TTime class return values converted to microseconds.
- *******************************************************************************/
-
- #define kTTimeID "slm:supp$time,1.1"
-
- class TTime : public TDoubleLong
- {
- public:
- MPWC TTime();
- MPWC TTime(unsigned long microseconds);
- MPWC TTime(const TDoubleLong&);
- MPWC TTime(const TTime&);
- virtual ~ MPWC TTime();
-
- void SetTime(const TTime&);
-
- void SetMicroseconds(unsigned long);
- virtual void MPWC SetMilliseconds(unsigned long);
- virtual void MPWC SetSeconds(unsigned long);
-
- unsigned long GetMicroseconds() const;
- virtual unsigned long MPWC GetMilliseconds() const;
- virtual unsigned long MPWC GetSeconds() const;
- };
-
- /* -----------------------------------------------------------------
- Inline Methods for TTime
- ----------------------------------------------------------------- */
-
- inline void TTime::SetTime(const TTime& time)
- {
- fLoBits = time.fLoBits;
- fHiBits = time.fHiBits;
- }
-
- inline void TTime::SetMicroseconds(unsigned long val)
- {
- fLoBits = val;
- fHiBits = 0;
- }
-
- inline unsigned long TTime::GetMicroseconds() const
- {
- return fLoBits;
- }
-
- /*******************************************************************************
- ** CLASS TMicroseconds
- *******************************************************************************/
-
- #define kTMicrosecondsID "slm:supp$mics,1.1"
-
- class TMicroseconds : public TTime
- {
- public:
- MPWC TMicroseconds();
- MPWC TMicroseconds(unsigned long msecs);
- ~ MPWC TMicroseconds();
-
- operator unsigned long() const;
- virtual double MPWC ConvertToDouble() const;
- operator double() const;
-
- private:
- TMicroseconds(const TMicroseconds&);
- void operator=(const TMicroseconds&);
- };
-
- /* -----------------------------------------------------------------
- Inline Methods for TMicroseconds
- ----------------------------------------------------------------- */
-
- inline TMicroseconds::operator unsigned long() const
- {
- return GetMicroseconds();
- }
-
- inline TMicroseconds::operator double() const
- {
- return ConvertToDouble();
- }
-
- /*******************************************************************************
- ** CLASS TMilliseconds
- *******************************************************************************/
-
- #define kTMillisecondsID "slm:supp$mils,1.1"
-
- class TMilliseconds : public TTime
- {
- public:
- MPWC TMilliseconds();
- MPWC TMilliseconds(unsigned long msecs);
- ~ MPWC TMilliseconds();
-
- operator unsigned long() const;
- virtual double MPWC ConvertToDouble() const;
- operator double() const;
-
- private:
- TMilliseconds(const TMilliseconds&);
- void operator=(const TMilliseconds&);
- };
-
- /* -----------------------------------------------------------------
- Inline Methods for TMilliseconds
- ----------------------------------------------------------------- */
-
- inline TMilliseconds::operator unsigned long() const
- {
- return GetMilliseconds();
- }
-
- inline TMilliseconds::operator double() const
- {
- return ConvertToDouble();
- }
-
- /*******************************************************************************
- ** CLASS TSeconds
- *******************************************************************************/
-
- #define kTSecondsID "slm:supp$secs,1.1"
-
- class TSeconds : public TTime
- {
- public:
- MPWC TSeconds();
- MPWC TSeconds(unsigned long secs);
- ~ MPWC TSeconds();
-
- operator unsigned long() const;
- virtual double MPWC ConvertToDouble() const;
- operator double() const;
-
- private:
- TSeconds(const TSeconds&);
- void operator=(const TSeconds&);
- };
-
- /* -----------------------------------------------------------------
- Inline Methods for TSeconds
- ----------------------------------------------------------------- */
-
- inline TSeconds::operator unsigned long() const
- {
- return GetSeconds();
- }
-
- inline TSeconds::operator double() const
- {
- return ConvertToDouble();
- }
-
- /*******************************************************************************
- ** CLASS TTimeStamp
- *******************************************************************************/
-
- #define kTTimeStampID "slm:supp$tstm,1.1"
-
- class TTimeStamp : public TTime
- {
- public:
- MPWC TTimeStamp();
- virtual ~ MPWC TTimeStamp();
-
- virtual void MPWC SetTimeStamp();
-
- private:
- TTimeStamp(const TTimeStamp&);
- void operator=(const TTimeStamp&);
- };
-
- /*******************************************************************************
- ** CLASS TStopwatch
- *******************************************************************************/
-
- #define kTStopwatchID "slm:supp$stpw,1.1"
-
- class TStopwatch : public TTimeStamp
- {
- public:
- MPWC TStopwatch();
- virtual ~ MPWC TStopwatch();
-
- virtual void MPWC Reset();
-
- virtual unsigned long MPWC ElapsedMicroseconds() const;
- virtual unsigned long MPWC ElapsedMilliseconds() const;
- virtual unsigned long MPWC ElapsedSeconds() const;
-
- private:
- TStopwatch(const TStopwatch&);
- void operator=(const TStopwatch&);
- };
-
- /*******************************************************************************
- ** CLASS TTraceLog
- **
- ** An object for doing debug tracing with.
- ********************************************************************************/
-
- #define kTTraceLogID "slm:dbug$tlog,1.1"
-
- class TTraceLog : public TDynamic
- {
- public:
- MPWC TTraceLog();
- virtual ~ MPWC TTraceLog();
-
- virtual void MPWC Trace(char *formatStr, ...) const;
-
- // New methods
-
- Boolean IsTraceLogOn() const;
- void TraceLogOn();
- void TraceLogOff();
-
- virtual void MPWC TraceFormatted(char* outstr) const = 0;
- virtual void MPWC TraceUnformatted(void* argp) const;
-
- protected:
- void SetTracePool(TStandardPool*);
- TStandardPool* GetTracePool() const;
-
- private:
- TTraceLog(const TTraceLog&);
- void operator=(const TTraceLog&);
-
- Boolean fTracing;
- TStandardPool* fTracePool;
- };
-
- /* -----------------------------------------------------------------
- Inline Methods for TTraceLog
- ----------------------------------------------------------------- */
-
- inline Boolean TTraceLog::IsTraceLogOn() const
- {
- return fTracing;
- }
-
- inline void TTraceLog::TraceLogOn()
- {
- if (fTracePool != NULL)
- fTracing = true;
- }
-
- inline void TTraceLog::TraceLogOff()
- {
- fTracing = false;
- }
-
- inline void TTraceLog::SetTracePool(TStandardPool* pool)
- {
- fTracePool = pool;
- }
-
- inline TStandardPool* TTraceLog::GetTracePool() const
- {
- return fTracePool;
- }
-
- /*******************************************************************************
- ** Some inlines that rely on other inlines so we just do them here to prevent
- ** circular dependency problems.
- ********************************************************************************/
-
- /* -------------------------------------------------------------------------
- Inline methods for TArray
- ------------------------------------------------------------------------- */
-
- inline TStandardPool* TArray::GetGrowPool() const
- {
- return (TStandardPool*)TMemoryPool::RecoverPool(fArray);
- }
-
- #endif
-
- #endif
-